import { ref, computed } from 'vue';
import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', () => {
    const selectedKeys = ref(['/']);
    const userInfo = ref(JSON.parse(sessionStorage.getItem('userInfonbd') || '{}'));
    const isShowVideoDetail = ref(false);
    const websockets = ref(false);
    const yixiaoerIo = ref(false);
    const choosedClue = ref<any>([]);
    const pubInfo = ref({});
    const updataPub = ref(false);
    const isUpdataUser = ref(false);
    const showCreatMotalnumber = ref('');
    const updataStep = ref(0);
    const needInitWebsocket = ref(false);
    const authority = ref<any>({});
    const moreObj = ref<any>({});
    const liveInfo = ref<any>({});
    const textInfo = ref<any>({});
    const roleName = ref<any>(null);
    const doubleCount = computed(() => updataStep.value * 2);

    const setSelectedKeys = (paths: any) => {
        selectedKeys.value = [...[paths]];
    };
    const updataUserInfo = (obj: object) => {
        userInfo.value = { ...obj };
    };
    const getWebsockets = (isWebsockets: boolean) => {
        websockets.value = isWebsockets;
    };

    const getNeedInitWebsocket = (bool: boolean) => {
        needInitWebsocket.value = bool;
    };
    const getYixiaoerIo = (bool: boolean) => {
        yixiaoerIo.value = bool;
    };
    const getIsShowVideoDetail = (compId: string) => {
        const videoDetailCompIds = ['7b6d02d2d4bee4b505a370898cf17a64', '9948f431881f82c292c6eda7f8942f2b'];
        isShowVideoDetail.value = videoDetailCompIds.includes(compId);
    };
    const changeCreatMotal = (value: string) => {
        showCreatMotalnumber.value = value;
    };
    const changeUpdataStep = (value: number) => {
        updataStep.value = value;
    };
    const pubInfoHandle = (obj: any) => {
        if (obj.id == 'initpub') {
            updataPub.value = false;
            pubInfo.value = {};
        } else {
            updataPub.value = true;
            pubInfo.value = { ...obj };
        }
    };
    const checkUserInfoHandle = (value: boolean) => {
        isUpdataUser.value = value;
    };
    const getMenuListHandle = (obj: object) => {
        authority.value = { ...obj };
    };
    const updataMoreObj = (obj: object) => {
        moreObj.value = { ...obj };
    };
    const changeLiveInfo = (obj: object) => {
        liveInfo.value = { ...obj };
    };
    const changeTextInfo = (obj: object) => {
        textInfo.value = { ...obj };
    };
    const updataRoleName = (obj: any) => {
        if (obj) {
            roleName.value = { ...obj };
        } else {
            roleName.value = null;
        }
    };
    return {
        selectedKeys,
        userInfo,
        isShowVideoDetail,
        websockets,
        yixiaoerIo,
        choosedClue,
        pubInfo,
        updataPub,
        isUpdataUser,
        showCreatMotalnumber,
        updataStep,
        needInitWebsocket,
        authority,
        moreObj,
        liveInfo,
        textInfo,
        roleName,
        setSelectedKeys,
        updataUserInfo,
        getWebsockets,
        getNeedInitWebsocket,
        getYixiaoerIo,
        getIsShowVideoDetail,
        changeCreatMotal,
        changeUpdataStep,
        pubInfoHandle,
        checkUserInfoHandle,
        getMenuListHandle,
        updataMoreObj,
        changeLiveInfo,
        changeTextInfo,
        updataRoleName
    };
});
